package com.huawei.java.main.server;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dengguoli
 * @date 2022/3/16
 * @since jdk1.8
 */
public class ServerBandwidth {
    // 服务器名称
    private String[] site_name;

    // 服务器供应能力
    private Integer[] bandwidth;

    //每个服务器每份供应能力

    // 单个服务器name-bandwidth映射
    private Map<String, Integer> serverBandMap;


    public ServerBandwidth (List<String[]> csvFile) {
        this.site_name = new String[csvFile.size()-1];
        this.bandwidth = new Integer[csvFile.size()-1];
        this.serverBandMap = new HashMap<>(csvFile.size()-1);
        this.parseNames(csvFile);
        this.parseBand(csvFile);
        for (int i = 0; i < bandwidth.length; i ++) {
            serverBandMap.put(site_name[i], bandwidth[i]);
        }
    }

    public Map<String, Integer> getServerBandMap() {
        return serverBandMap;
    }

    public void setServerBandMap(Map<String, Integer> serverBandMap) {
        this.serverBandMap = serverBandMap;
    }

    private void parseBand(List<String[]> csvFile) {
        for (int i = 1; i < csvFile.size(); i++) {
            this.bandwidth[i-1] = Integer.valueOf(csvFile.get(i)[1]);
        }
    }

    private void parseNames(List<String[]> csvFile) {
        for (int i = 1; i < csvFile.size(); i++) {
            this.site_name[i-1] = csvFile.get(i)[0];
        }
    }

    public String[] getSite_name() {
        return site_name;
    }

    public void setSite_name(String[] site_name) {
        this.site_name = site_name;
    }

    public Integer[] getBandwidth() {
        return bandwidth;
    }

    public void setBandwidth(Integer[] bandwidth) {
        this.bandwidth = bandwidth;
    }
}
